package com.ls.socketio.bean;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.hibernate.FlushMode;
import org.hibernate.annotations.Fetch;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 楼栋层数
 * @author liShan
 * @date 2019/9/3 11:23
 */
@Getter
@Setter
@ToString
@Entity(name = "layer")
public class LayerInfo implements Serializable {

    @Id
    @Column(name = "layer_id")
    private Long layerId;

    @Column(name = "build_id")
    private int buildId;

    @Column(name = "layer_num")
    private int layerNum;

    @OneToMany(cascade = CascadeType.DETACH, fetch = FetchType.EAGER)
    @JoinColumn(name = "layer_id")
    private List<RoomInfo> roomInfos;

    public LayerInfo() { }

    private LayerInfo(Builder builder) {
        this.layerId = builder.layerId;
        this.buildId = builder.buildId;
        this.layerNum = builder.layerNum;
        this.roomInfos = builder.roomInfos;
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder{

        private Long layerId;
        private int buildId;
        private int layerNum;
        private List<RoomInfo> roomInfos;

        public Builder layerId(Long layerId){
            this.layerId = layerId;
            return this;
        }

        public Builder buildId(int buildId){
            this.buildId = buildId;
            return this;
        }

        public Builder layerNum(int layerNum){
            this.layerNum = layerNum;
            return this;
        }

        public Builder layerInfos(List<RoomInfo> roomInfos){
            this.roomInfos = roomInfos;
            return this;
        }

        public LayerInfo build() {
            return new LayerInfo(this);
        }

    }

}
